#!/bin/bash

function filter_kallsyms()
{
	rm -f kallsyms.*
	gawk 'BEGIN {text="kallsyms.t"; var="kallsyms.v" }  { 
		if (NF == 3) { 
			if ($2 == "t" || $2 == "T") 
				print $1 " " $3 >> text  
			else  
				print $1 " " $3 >> var 
		}}' /proc/kallsyms
	sort kallsyms.t > kallsyms.text
	sort kallsyms.v > kallsyms.var
	rm -f kallsyms.t kallsyms.v
	while read line; do echo ${line%.*}; done <kallsyms.var > kallsyms.var1
}

function filter_dwarf()
{
	rm -f dwarf.var
	gawk -v out="dwarf.v" '/^[[:blank:]]*\+/ {
		print $2 " " substr($1, 2) >> out
	}' $1
	sort dwarf.v > dwarf.var
	rm -f dwarf.v
}

if (($# != 1)); then
	echo "Usage: $0 vmlinux"
	exit 1
fi

./dwarfaddr $1 > dwarf.all

filter_kallsyms

filter_dwarf dwarf.all

echo "kallsyms variables(non t/T):"
wc kallsyms.var
echo "dwarf variables:"
wc dwarf.var
echo "dwarf variables not in kallsyms:"
comm -23 dwarf.var kallsyms.var |wc
echo "after trimmed kallsyms .xxx postfix"
comm -23 dwarf.var kallsyms.var1 |wc

